package com.ahpu.jym.messagealert.main;

import com.ahpu.jym.messagealert.MailListening;
import com.ahpu.jym.messagealert.PhoneCallListen;
import com.ahpu.jym.messagealert.SmsListening;

import net.rim.device.api.system.Application;
import net.rim.device.api.system.SystemListener;

/**
 * 
 * @ClassName: ApplicationInit
 * @Description: Application 设置监听和延迟启动
 * @author sijilian sijilian.90@gmail.com
 * @date 2012-12-6 上午9:52:33
 */
public class ApplicationInit extends Application implements SystemListener {

	/**
	 * 
	* <h4>Title: </h4>
	* <p>Description: </p>
	 */
	public ApplicationInit() {
	}

	/**
	 * 
	 *<h4>Title: doStartupWorkLater</h4>
	 *<p>Description: 开机延迟启动</p>
	 */
	public void doStartupWorkLater() {
		invokeLater(new Runnable() {
			public void run() {
				doStartupWork();
			}
		});
	}

	/**
	 * 
	 *<h4>Title: doStartupWork</h4>
	 *<p>Description: 开机启动后的操作 ，线程操作</p>
	 */
	public void doStartupWork() {
		
		//消息（邮件）的监听器
		new Thread(){
			public void run() {
				MailListening listening= new MailListening();
				listening.WaitforConfig();
			}
		}.start();
		//监听电话
		new Thread(){
			public void run() {
				new PhoneCallListen();
			}
		}.start();
		
		//SMS 监听
		SmsListening listening = new SmsListening();
		listening.start();


	}

	/*
	 * 前台显示
	 * @see net.rim.device.api.system.Application#acceptsForeground()
	 */
	protected boolean acceptsForeground() {
		
		return false;
	}
	
	
	public void batteryGood() {
		// TODO Auto-generated method stub

	}

	
	public void batteryLow() {
		// TODO Auto-generated method stub

	}

	public void batteryStatusChange(int status) {
		// TODO Auto-generated method stub

	}

	public void powerOff() {
		// TODO Auto-generated method stub

	}

	/**
	 * 开机启动
	 */
	public void powerUp() {
		// TODO Auto-generated method stub

		try {
			Thread.sleep(4000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		doStartupWork();
		removeSystemListener(this);
	}

}
